<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../css/mui.picker.min.css" />
		<link rel="stylesheet" href="../css/iconfont.css">
		<style>
			.mui-content-padded{margin:5px 0 0 0;}
			.mui-row-list span{float: left; line-height:33px; width:20%;}
			.mui-row-list select{float: left; line-height:14px; font-size:14px; margin-top:2px; margin-left: 5px;}
			.mui-btn-block{margin-bottom:0; padding:6px;}
			.mui-col-sm-12{ border-top: 1px solid #D1D1D1; width:100%; padding-top:5px; font-size:14px;}
			.mui-switch:before {content: '否'; color: #999;}
			.mui-switch.mui-active:before {content: '是'; color: #fff;}
			.mui-switch.two:before {content: '正常'; color: #999;}
			.mui-switch.two.mui-active.two:before {content: '撤销'; color: #fff;}
			.mui-table-view-cell.mui-active{ display:block;}
			input{border-width:0; text-align: right; font-size:14px; line-height: 26px;}
			.bottom_soild{border-bottom: 1px solid #DDDDDD; margin-right: 5px;}
			.mui-switch{
				border-color: #007AFF;
				background-color: #007AFF;
				border-width: 1px;
			}
			.mui-switch:before {content: '无'; color: #fff;}
			.mui-switch.mui-active:before {content: '有'; color: #fff;}
			.mui-switch.mui-active {
				border-color: #fd933b;
				background-color: #fd933b;
			}
			.submit{
				margin:0 auto 10px auto; 
				width:200px; 
				height:35px; 
				line-height: 35px; 
				background-color:#007AFF; 
				text-align: center; 
				color: #FFFFFF; 
				border-radius: 10px;
				margin-top: 10px;
			}
		</style>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">辅助检查</h1>
		</header>
		<div class="mui-conten" style="margin-top:50px;">
			<ul class="mui-table-view">
				<div class="mui-row">
					<div class="mui-col-sm-12 mui-col-xs-12">
						<li class="mui-table-view-cell">
							<div style="width: 100%; float: left;">
								<div style="float: left; font-size:16px; height: 30px; line-height: 30px;">药物不良反应</div>
								<div class="mui-switch" id="mySwitch1" style="float: right; font-size:16px; height: 30px;">
								  <div class="mui-switch-handle"></div>
								</div>
							</div>
							<div id='a1' style="float: left; font-size:16px; width: 100%; height: 30px; margin-top: 5px; display: none;">
								<input id='a1text' class="ui-alert bottom_soild" placeholder="请输入" style="width:100%; text-align: left; line-height: 26px;"/>
							</div>
						</li>
						<li class="mui-table-view-cell">
							<div style="width: 100%; float: left;">
								<div style="float: left; font-size:16px; height: 30px; line-height: 30px;">并发症或合并症</div>
								<div class="mui-switch" id="mySwitch2" style="float: right; font-size:16px; height: 30px;">
								  <div class="mui-switch-handle"></div>
								</div>
							</div>
							<div id='a2' style="float: left; font-size:16px; width: 100%; height: 30px; margin-top: 5px; display: none;">
								<input id='a2text' class="ui-alert bottom_soild" placeholder="请输入" style="width:100%; text-align: left; line-height: 26px;"/>
							</div>
						</li>
					</div>
				</div>
			</ul>
			<div style="margin-left:0.9rem; line-height:35px;">转诊</div>
			<ul class="mui-table-view">
				<div class="mui-row">
					<div class="mui-col-sm-12 mui-col-xs-12">
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 14px; width: 100px; line-height: 26px;">科别</div>
							<input style="width:45%; float: right;" id='dep' class="ui-alert bottom_soild"  placeholder="请输入"/>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 14px; width: 100px; line-height: 26px;">原因</div>
							<input style="width:45%; float: right;" id='why' class="ui-alert bottom_soild"  placeholder="请输入"/>
						</li>
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 14px; width: 140px; line-height: 26px;">2周内随访，随访结果</div>
							<input style="width:45%; float: right;" id='week' class="ui-alert bottom_soild"  placeholder="请输入"/>
						</li>
					</div>
				</div>
			</ul>
			<ul class="mui-table-view" style="margin-top: 5px;">
				<div class="mui-row">
					<div class="mui-col-sm-12 mui-col-xs-12">
						<li class="mui-table-view-cell">
							<div style="float: left; font-size: 14px; width: 100px; line-height: 26px;">处理意见</div>
							<input id='opinion' class="ui-alert bottom_soild" placeholder="请输入" style="width:50%; float: right;"/>
						</li>
					</div>
				</div>
			</ul>
			<div onclick="submit()" class="submit" >保存</div>
		</div>
		<script src="../js/mui.js"></script>
		<script src="../js/mui.picker.min.js"></script>
		<script src="../js/jquery.min-1.11.1.js"></script>
		<script src="../js/request.js"></script>
		<script type="text/javascript">
			//获取变量
			var self = localStorage.getItem("name");
			var dataold = JSON.parse(self);
			var obj = dataold.obj;
			var selfdata ="";
			var listdata ="";
			mui.plusReady(function(){
				var self = plus.webview.currentWebview();
					listdata = self.data;
					visitId = self.visitdata;
					selfdata = JSON.parse(listdata)
					console.log(selfdata.ehrId)
					console.log(self.arcid)
				var date1 = new Date();
				var year1=date1.getFullYear(); 
				var month1=date1.getMonth()+1;
				var day1=date1.getDate();
				var h1=date1.getHours();
				var m1=date1.getMinutes();
				var s1=date1.getSeconds();
					month1 =(month1<10 ? "0"+month1:month1); 
					day1 =(day1<10 ? "0"+day1:day1); 
					h1 =(h1<10 ? "0"+h1:h1); 
					m1 =(m1<10 ? "0"+m1:m1); 
					s1 =(s1<10 ? "0"+s1:s1);
					createDate = (year1.toString()+'-'+month1.toString()+'-'+day1.toString()+' '+h1.toString()+':'+m1.toString()+':'+s1.toString());
					modifyDate = (year1.toString()+'-'+month1.toString()+'-'+day1.toString()+' '+h1.toString()+':'+m1.toString()+':'+s1.toString());
					ehrId = selfdata.ehrId;
					tbId = self.arcid;
				if(self.second != ""){
					first = JSON.parse(self.first);
					second = JSON.parse(self.second);
					id = first.id;
					createUser = first.createUser;
					createDate = first.createDate;
					console.log(self.second);
					for(var i=0; i<second.length; i++){
						if(second[i].questionId == "907"){
							if(second[i].answerId == "2"){
								document.getElementById("a1").style.display = "block";
								document.getElementById("mySwitch1").classList.add('mui-active');
								document.getElementById("a1text").value = second[i].answer;
							}else{
								document.getElementById("a1").style.display = "none";
								document.getElementById("mySwitch1").classList.remove('mui-active');
							}
						}
						if(second[i].questionId == "908"){
							if(second[i].answerId == "2"){
								document.getElementById("a2").style.display = "block";
								document.getElementById("mySwitch2").classList.add('mui-active');
								document.getElementById("a2text").value = second[i].answer;
							}else{
								document.getElementById("a2").style.display = "none";
								document.getElementById("mySwitch2").classList.remove('mui-active');
							}
						}
						if(second[i].questionId == "333"){
							document.getElementById("dep").value = second[i].answer;
						}
						if(second[i].questionId == "334"){
							document.getElementById("why").value = second[i].answer;
						}
						if(second[i].questionId == "909"){
							document.getElementById("week").value = second[i].answer;
						}
						if(second[i].questionId == "910"){
							document.getElementById("opinion").value = second[i].answer;
						}
					}
				}
			})
			//赋值
			var id = 0;
			var visitId= 0;
			var ehrId = "";
			var tbId ="";//肺结核专档id
			var createDate = "";
			var createUserid = obj.id;
			var modifyDate = "";
			var modifyUserid = obj.id;
			var drugreac = ""
			var symptoms = ""
			var drugreacid = "1"
			var symptomsid = "1"
			mui.init()
			(function($) {
				$.init();
				var result = $('#result')[0];
				var btns = $('.btn');
				btns.each(function(i, btn) {
					btn.addEventListener('tap', function() {
						var _self = this;
						if(_self.picker) {
							_self.picker.show(function (rs) {
								result.innerText = rs.text;
								_self.picker.dispose();
								_self.picker = null;
							});
						} else {
							if(i == 0){
								var picker = new mui.PopPicker();
								 picker.setData([{value:'1',id:'001',text:' 正常'},{value:'2',id:'002',text:' 异常'}]);
								 picker.show(function (selectItems) {
									 $('#result4')[0].value = selectItems[0].text;
								  })
							} else {
								var picker = new mui.PopPicker();
								 picker.setData([{value:'1',id:'001',text:' 正常'},{value:'2',id:'002',text:' 异常'}]);
								 picker.show(function (selectItems) {
									 $('#result6')[0].value = selectItems[0].text;
								  })
							}
						}
						
					}, false);
				});
			})(mui);
			//切换
			document.getElementById("mySwitch1").addEventListener("toggle",function(event){
				if(event.detail.isActive){
						document.getElementById("a1").style.display="block";
				}else{
						document.getElementById("a1").style.display="none";
				}
			})
			document.getElementById("mySwitch2").addEventListener("toggle",function(event){
				if(event.detail.isActive){
						document.getElementById("a2").style.display="block"
				}else{
						document.getElementById("a2").style.display="none"
				}
			})
			//提交
			function submit(){
				if($("#mySwitch1").hasClass("mui-active")){
					drugreacid = "2";
					drugreac = document.getElementById("a1text").value;
				}else{
					drugreacid = "1";
					drugreac = "";//药物不良反应
				}
				if($("#mySwitch2").hasClass("mui-active")){
					symptomsid = "2";
					symptoms = document.getElementById("a2text").value;
				}else{
					symptomsid = "1";
					symptoms = "";//并发症
				}
				var dataobj=[
					//不良反应
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"907",
					"answerId":drugreacid,
					"answer":drugreac,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},	
					//并发症
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"908",
					"answerId":symptomsid,
					"answer":symptoms,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//科别	
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"333",
					"answerId":"0",
					"answer":mui("#dep")[0].value,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//原因
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"334",
					"answerId":"0",
					"answer":mui("#why")[0].value,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//2周内随访	
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"909",
					"answerId":"0",
					"answer":mui("#week")[0].value,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid},
					//处理意见
					{'id':id,
					'ehrId':ehrId,
					'tbId':tbId,
					"visitId":visitId,
					"questionId":"910",
					"answerId":"0",
					"answer":mui("#opinion")[0].value,
					"expectedAnswerId":"0",
					"expectedAnswer":null,
					"createDate":createDate,
					"modifyDate":modifyDate,
					"createUserid":createUserid,
					"modifyUserid":modifyUserid}
				]		
				$.ajax({
					type: 'post',
					url:getRequestUrl.url+"/mobile/ehr/TbVisitAddition/addOrUpdate",
					data:JSON.stringify(dataobj),
					dataType:"json",
					contentType : 'application/json;charset=utf-8',
					success : function(data) {
						if(data.status==1){
							alert("提交成功")
							mui.openWindow({
								url: 'follow_up_add.html', 
								id:'follow_up_add',
								extras:{
									
								}
							});
						}else{
							alert(data.message);
						}
					},
					error:function(xhr,type,errorThrown){
						
					}
				})
			}
		</script>
	</body>
</html>